package com.promise.jokerdream.ui.components

import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage

/**
 * 用户头像组件
 * 支持从QQ头像API获取真实头像
 */
@Composable
fun UserAvatar(
    userId: String?,
    size: Dp = 64.dp,
    spec: Int = 100,
) {
    AsyncImage(
        model = if (userId != null) {
            "http://q2.qlogo.cn/headimg_dl?dst_uin=$userId&spec=$spec"
        } else {
            null
        },
        contentDescription = "用户头像",
        modifier = Modifier
            .size(size)
            .clip(CircleShape),
        contentScale = ContentScale.Crop,
        error = rememberVectorPainter(
            image = Icons.Default.Person
        ),
        placeholder = rememberVectorPainter(
            image = Icons.Default.Person
        )
    )
}